<template>
    <div class="container">
        <!-- 标题区域 -->
        <h3>{{newsinfo.title}}</h3>
        <p class="zy">
            <span>发表时间：{{newsinfo.add_time | dateFormat}}</span>
            <span>点击次数：{{newsinfo.click}}</span>
        </p>
        <hr>
        <!-- 内容区域 -->
        <div class="content" v-html="newsinfo.content">          
        </div>
        <!-- 评论子组件区域 -->
        <comment-box :id="this.id"></comment-box>
    </div>
</template>

<script>
import {Toast} from 'mint-ui'
// 导入评论子组件
import comment from "../subcomponents/comment.vue"
export default {
    data(){
        return {
            id: this.$route.params.id,  //将url传递过来的id值挂载到data上，方便调用
            newsinfo:{}  //只有一组对象，故不需要数组
        }
    },
    created(){
		this.getnewsinfo();
	},
    methods:{
        getnewsinfo(){
            this.$http.get("api/getnew/"+this.id).then(result=>{
                if(result.body.status==0){
                    this.newsinfo=result.body.message[0]
                }else{
                    Toast("加载新闻详情失败！")
                }
            })
        }
    },
    components:{
        'comment-box':comment
    }
}
</script>

<style lang="scss">
.container{
    padding-left:4px;
    padding-right:4px;  
    h3{
        text-align: center;
        color:red;
        font-size:16px;
    }
    .zy{
        display: flex;
        justify-content: space-between;
        font-size:12px;
        color:blue;
    }
    .content{
        
    }
}
</style>

